package com.javaspeak.designpatterns.go4.structural.proxy;

/**
 * This proxy class proxies the shape Subject.  After calling drawShape() on
 * the subject it logs to Systm.out how many times the drawShape() method has
 * been called.
 * <p>
 * Note that the relationship to the subject is ususally determined at compile
 * time with the proxy pattern.
 * <p>
 * With the decorator pattern which is quite similar the relationship is
 * usually defined at runtime.  A runtime relationship means that the class
 * being decorated is passed in via a constructor or setter and a compile time
 * relationship means the proxy is hard coded to proxy a specific class.
 * <p>
 * Decorators are often chained together while proxies are not chained.
 *
 * @author John Dickerson
 */
public class TriangleProxy implements Shape {

    private Shape subject;
    private int numberTimesInvoked;

    /**
     * Constructor
     * <p>
     * Instantiates subject we are proxying
     */
    public TriangleProxy(){

        this.subject = new Triangle();
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.structural.proxy.Shape#drawShape()
     */
    @Override
    public void drawShape() {

        this.subject.drawShape();
        numberTimesInvoked++;

        System.out.println(
              "drawShape() has been invoked " + numberTimesInvoked + " times" );
    }
}
